<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" 
    import="com.microsoft.windowsazure.services.core.storage.*,
com.microsoft.windowsazure.services.table.client.*,
com.microsoft.windowsazure.services.table.client.TableQuery.*, MyVM.*,
java.util.Date"       
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Windows Azure VM - Java</title>
</head>
<body>
<%

// ganti nilai AccountKey
String storageConnectionString = 
			"DefaultEndpointsProtocol=http;" + 
			"AccountName=<??>;" + 
			"AccountKey=<??>";
			
			CloudStorageAccount storageAccount =
				    CloudStorageAccount.parse(storageConnectionString);

			CloudTableClient tableClient = storageAccount.createCloudTableClient();
		    CloudTable table = tableClient.getTableReference("people");
		    table.createIfNotExist();

		    Date time = new Date();
		    CustomerEntity customer1 = new CustomerEntity("User", time.toString());
		    customer1.setEmail("user@test.com");
		    customer1.setPhoneNumber("111-111-111");

		    // Create an operation to add the new customer to the people table.
		    TableOperation insertCustomer1 = TableOperation.insert(customer1);

		    // Submit the operation to the table service.
		    TableResult result  =tableClient.execute("people", insertCustomer1);
		    String ret = result.toString();
%>
	<p>Response insert from Azure Table: </p>
	<%=ret %>
	<br><br>
	<%

	TableQuery<CustomerEntity> partitionQuery =
		    TableQuery.from("people", CustomerEntity.class);

		String str = "";
		for (CustomerEntity entity : tableClient.execute(partitionQuery)) {
		    str =  str + "<p>" + entity.getPartitionKey() + ";" + entity.getRowKey() + 
		        ";" + entity.getEmail() + ";" + entity.getPhoneNumber() + "</p>";
	}
	%>
	<p>List of data from Azure Table: </p>
	<%=str %>
</body>
</html>